using UnityEngine;
using System.Collections;

public class OrbitAroundObject : MonoBehaviour {
	
	// NOTE TO SELF: explain these variables
	
	public Transform objectToOrbit;		// The body to orbit around
	public float orbitSpeed = 40.0f;		//
	public float orbitDistance = 5.0f;
	
	private float currentRotation;
	private Quaternion quatRot;
	private Vector3 radius;
	Vector3 newEulerAngles;
	
	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(objectToOrbit)
		{
			currentRotation += orbitSpeed * Time.deltaTime;
			radius.Set(orbitDistance, 0.0f, 0.0f);
			newEulerAngles.Set(0.0f, currentRotation, 0.0f);
	    	quatRot.eulerAngles = newEulerAngles;
	    	transform.eulerAngles = newEulerAngles;
			transform.position = quatRot * radius + objectToOrbit.position;
		}
	}
}


// CREDIT: http://answers.unity3d.com/questions/32494/rotating-a-game-object-around-another-controlled-g.html